package com.oig.sys.auth.dao;

import com.oig.sys.auth.entity.TbJobRole;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
@author wuxl
*/
public interface ITbJobRoleDao extends JpaRepository<TbJobRole, Integer> {

	TbJobRole getByRoleIdAndJobId(Integer roleId, Integer jobId);

	@Query("select jr.id from TbJobRole jr where jr.id not in(:idList) and jr.jobId=:jobId")
	List<Integer> findAllDelId(@Param("jobId") Integer jobId, @Param("idList") List<Integer> idList);

	@Query("select jr.id from TbJobRole jr where jr.roleId=:roleId")
	List<Integer> findAllIdByRoleId(@Param("roleId") Integer roleId);

	@Query("select jr.id from TbJobRole jr where jr.jobId=:jobId")
	List<Integer> findAllIdByJobId(@Param("jobId") Integer jobId);

	@Modifying
	@Query("delete from TbJobRole jr where jr.id in(:idList)")
	void deleteByIdList(@Param("idList") List<Integer> idList);


	@Query("select jr.roleId from TbJobRole jr where jr.jobId in(:jobIdList)")
	List<Integer> findAllRoleIdByJobIdIn(@Param("jobIdList") List<Integer> jobIdList);

}
